//
//  ConsultView.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/7.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "ConsultView.h"

@implementation ConsultView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.alpha = 0;
        //背景
        UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, -NAVI_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
        bgView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.75];
        [self addSubview:bgView];
//        UITapGestureRecognizer * bgTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgTapGestureClick)];
//        [bgView addGestureRecognizer:bgTapGesture];
        //白色背景
        UIView * whiteBGView = [[UIView alloc] init];
        whiteBGView.backgroundColor = [UIColor whiteColor];
        whiteBGView.layer.cornerRadius = 6;
        whiteBGView.layer.masksToBounds = YES;
        [self addSubview:whiteBGView];
        //标题
        UILabel * titleLab = [[UILabel alloc] init];
        titleLab.text = @"咨询";
        titleLab.font = DEF_FontSize_14;
        titleLab.textColor = [UIColor blackColor];
        titleLab.textAlignment = NSTextAlignmentCenter;
        [whiteBGView addSubview:titleLab];
        //次标题
        UILabel * subTitleLab = [[UILabel alloc] init];
        subTitleLab.text = @"不确定是否可以加入，请咨询客服";
        subTitleLab.font = DEF_FontSize_12;
        subTitleLab.textColor = getColor(@"c6c6c6");
        subTitleLab.textAlignment = NSTextAlignmentCenter;
        [whiteBGView addSubview:subTitleLab];
        //电话
        UIButton * phoneBtn = [[UIButton alloc] init];
        [phoneBtn setTitle:@"400-888-8888" forState:UIControlStateNormal];
        [phoneBtn setTitleColor:getColor(@"6cdaba") forState:UIControlStateNormal];
        phoneBtn.titleLabel.font = DEF_FontSize_12;
        [phoneBtn setBackgroundColor:[UIColor whiteColor]];
        [phoneBtn addTarget:self action:@selector(phoneBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:phoneBtn];
        //分割线
        UIView * lineView = [[UIView alloc] init];
        lineView.backgroundColor = getColor(@"f7f7f7");
        [self addSubview:lineView];
        //知道了
        UIButton * knownBtn = [[UIButton alloc] init];
        [knownBtn setTitle:@"知道了" forState:UIControlStateNormal];
        [knownBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        knownBtn.titleLabel.font = DEF_FontSize_14;
        [knownBtn setBackgroundColor:[UIColor clearColor]];
        [knownBtn addTarget:self action:@selector(knowBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:knownBtn];
        __weak __typeof(self)weakSelf = self;
        [whiteBGView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.mas_left).mas_offset(29/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.mas_right).mas_offset(-29/WIDTH_6_SCALE);
            make.center.equalTo(weakSelf).centerOffset(CGPointMake(0, -60/WIDTH_6_SCALE));
            make.height.mas_offset(150/WIDTH_6_SCALE);
        }];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
            make.top.equalTo(whiteBGView.mas_top).mas_offset(17/WIDTH_6_SCALE);
            make.height.mas_offset(18/WIDTH_6_SCALE);
        }];
        [subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
            make.top.equalTo(titleLab.mas_bottom).mas_offset(17/WIDTH_6_SCALE);
            make.height.mas_offset(12/WIDTH_6_SCALE);
        }];
        [phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
            make.top.equalTo(subTitleLab.mas_bottom).mas_offset(13/WIDTH_6_SCALE);
            make.height.mas_offset(12/WIDTH_6_SCALE);
        }];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
            make.top.equalTo(phoneBtn.mas_bottom).mas_offset(17/WIDTH_6_SCALE);
            make.height.mas_offset(1/WIDTH_6_SCALE);
        }];
        [knownBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
            make.top.equalTo(lineView.mas_bottom);
            make.bottom.equalTo(whiteBGView.mas_bottom);
        }];
    }
    return self;
}

#pragma mark - action
- (void)knowBtnClick{
    NSLog(@"点击");
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0 ;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (void)show{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 1;
    }];
}

- (void)phoneBtnClick{
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"400-888-8888"];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self addSubview:callWebview];

}

@end
